﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace Douban.Api.Web
{
    public class AuthorizedResponse
    {
        private readonly HttpWebResponse _response;
        private string _responseData;

        public AuthorizedResponse(HttpWebResponse response)
        {
            _response = response;
        }

        public HttpStatusCode StatusCode
        {
            get { return _response.StatusCode; }
        }

        public string ContentEncoding
        {
            get { return _response.ContentEncoding; }
        }

        public long ContentLength
        {
            get { return _response.ContentLength; }
        }

        public string ContentType
        {
            get { return _response.ContentType; }
        }

        public string Data
        {
            get
            {
                if (_responseData == null)
                {
                    StreamReader reader = new StreamReader(_response.GetResponseStream());
                    _responseData = reader.ReadToEnd();
                    reader.Close();
                }

                return _responseData;
            }
        }

        public void Close()
        {
            _response.Close();
        }
    }
}
